package com.danskin.wechat.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.danskin.wechat.dao.WxFansInfoDao;
import com.danskin.wechat.entity.WxFansInfo;
import com.danskin.wechat.entity.example.WxFansInfoExample;
import com.danskin.wechat.service.WxFansInfoService;
import com.danskin.wechat.util.LogUtil;
import com.danskin.wechat.util.StringUtil;

@Service
public class WxFansInfoServiceImpl implements WxFansInfoService {

	@Autowired
	private WxFansInfoDao fansInfoDao;

	@Override
	public WxFansInfo getWxFansInfoByOpenId(String openId) {
		WxFansInfo wxFansInfo = null;

		try {
			if (!StringUtil.isNullOrEmpty(openId)) {
				wxFansInfo = fansInfoDao.selectByOpenId(null, openId); 
			}
		} catch (Exception ex) {
			LogUtil.error("查询粉丝数据异常：" + ex.getMessage());
		}

		return wxFansInfo;
	}

	@Override
	public int insertSelective(WxFansInfo record) {
		LogUtil.info("=======新建粉丝参数：" + ToStringBuilder.reflectionToString(record));
		Integer insertCount = 0;
		try {
			insertCount = fansInfoDao.insertSelective(record);
		} catch (Exception e) {
			LogUtil.error("=======新建粉丝异常", e);
		}
		return insertCount;
	}

	@Override
	public List<WxFansInfo> selectByExample(WxFansInfoExample example) {
		LogUtil.info("=======查询符合条件的粉丝信息参数：" + ToStringBuilder.reflectionToString(example));

		List<WxFansInfo> fansInfoList = new ArrayList<WxFansInfo>();

		try {
			fansInfoList = fansInfoDao.selectByExample(example);
		} catch (Exception e) {
			LogUtil.error("========查询符合条件的粉丝信息异常", e);
		}
		return fansInfoList;
	}

	@Override
	public Long selectWxFansInfoCount(WxFansInfo param) {
		LogUtil.info("=======查询符合条件的粉丝数参数：" + ToStringBuilder.reflectionToString(param));

		Long selectCount = 0L;

		try {
			selectCount = fansInfoDao.selectWxFansInfoCount(param);
		} catch (Exception e) {
			LogUtil.error("=======查询符合条件的粉丝数异常", e);
		}
		return selectCount;
	}

	@Override
	public Map<String, Object> selectFanseInfoAndMobileByOpenId(Map<String, Object> map) {
		Map<String, Object> map2 = fansInfoDao.selectFanseInfoAndMobileByOpenId(map);
		return map2;
	}

}
